package cn.wggf.dev.qcgg.ws;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.wggf.dev.qcgg.pojo.RecordInterface;
import cn.wggf.dev.qcgg.service.CheckStationService;
import cn.wggf.dev.qcgg.service.QcggService;
import cn.wggf.dev.qcgg.service.RecordInterfaceService;
import cn.wggf.dev.qcgg.service.impl.CheckStationServiceImpl;
import cn.wggf.dev.qcgg.service.impl.QcggServiceImpl;
import cn.wggf.dev.qcgg.service.impl.RecordInterfaceServiceImpl;
import cn.wggf.dev.qcgg.util.ResultUtil;

public class QcggWebService {
	
	private Logger log = LoggerFactory.getLogger(QcggWebService.class);
	private CheckStationService checkStationService = new CheckStationServiceImpl();
	private RecordInterfaceService recordInterfaceService = new RecordInterfaceServiceImpl();
	private QcggService qcggService = new QcggServiceImpl();
	
	
	public String queryQcggByPPAndGGXH(String GUID,String PP,String GGXH) {
		log.info("接口调用: 调用者的GUID({})信息", GUID);
		log.info("接口调用: 根据品牌和公告型号({})查询汽车公告信息参数PP", PP);
		log.info("接口调用: 根据品牌和公告型号({})查询汽车公告信息参数GGXH", GGXH);
		String code = "0";
		String message = "您无权限查询，请确认后操作！";
		Object data = null;
		List<Map<String, Object>> queryCsn = checkStationService.queryCsn();
		if (!"".equals(GUID) && GUID != null) {		
			for (Map<String, Object> map : queryCsn) {
				log.info("接口调用: 调用者的cSN是"+map.get("cSN"));
				if (map.get("cSN").equals(GUID)) {
					RecordInterface recordInterface = new RecordInterface();
					recordInterface.setCid(Integer.parseInt(GUID));
					recordInterface.setGtime(new Date());
					recordInterfaceService.insert(recordInterface);
					List<Map<String, Object>> qcggList = qcggService.getQcggByConditions(PP,GGXH);
					if (qcggList==null) {
						code = "0";
						message = "查询成功,不存在!";
						data = null;
					}else {
						code = "1";
						message = "查询成功";
						data = qcggList;
					}
				
					break;
				}
			}
		}
		// 将获取的用户信息转为 json 字符串并返回
		return ResultUtil.urlEncoder(code, message, data);
	}
	
	public String queryQcggImagesByID(String GUID,Integer ID) {
		log.info("接口调用: 调用者的GUID({})信息", GUID);
		log.info("接口调用: 根据品牌和公告型号({})查询汽车公告信息参数ID", ID);
		String code = "0";
		String message = "您无权限查询，请确认后操作！";
		Object data = null;
		List<Map<String, Object>> queryCsn = checkStationService.queryCsn();
		if (!"".equals(GUID) && GUID != null) {
			System.out.println("进来来了");
			for (Map<String, Object> map : queryCsn) {
				System.out.println("见来了");
				log.info("接口调用: 调用者的cSN是"+map.get("cSN"));
				if (map.get("cSN").equals(GUID)) {
					RecordInterface recordInterface = new RecordInterface();
					recordInterface.setCid(Integer.parseInt(GUID));
					recordInterface.setGtime(new Date());
					recordInterfaceService.insert(recordInterface);
					List<Map<String, Object>> qcgg= qcggService.getQcggById(ID);
					if (qcgg==null) {
						code = "0";
						message = "查询成功,ID不存在!";
						data = null;
					}else {
						code = "1";
						message = "查询成功";
						data = qcgg;
					}
				}
			}
		}	
		return ResultUtil.urlEncoder(code, message, data);
	}
}
